<%@ Page Language="C#" MasterPageFile="~/Views/Shared/MasterPage.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Animoso.Domain.NewsItem>>" %>


<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Animoso: Nieuws
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 <h4>Ongepubliceerde berichten</h4>
 <fieldset>
    <table>
    <% foreach (var newsItem in Model.Where(x => x.Published == false))
    {
           %>
        <tr id="newsItem_<%=newsItem.Id %>">
            <td><b><%=newsItem.Title %></b></td>
            <td><%=newsItem.DateTime.ToShortDateString() %></td>
            <td><%=newsItem.Author.Name %></td>
            <td><a href="<%=Url.Action("Edit", "News", new { id = newsItem.Id}) %>"><img src="Content/Images/Text-Edit-icon.png" /></a></td>
            <td><a id="delete_<%=newsItem.Id %>" class="deleteNewsItem" href="#"><img src="Content/Images/File-Delete-icon.png" /></a></td>
        </tr>
    <% } %>        
    </table>
 </fieldset>
 <h4>Gepubliceerde berichten</h4>
 <fieldset>
    <table>
    <% foreach (var newsItem in Model.Where(x => x.Published == true))
    {
           %>
        <tr id="newsItem_<%=newsItem.Id %>">
            <td><b><%=newsItem.Title %></b></td>
            <td><%=newsItem.DateTime.ToShortDateString() %></td>
            <td><%=newsItem.Author.Name %></td>
            <td><a href="<%=Url.Action("Edit", "News", new { id = newsItem.Id}) %>"><img src="Content/Images/Text-Edit-icon.png" /></a></td>
            <td><a id="delete_<%=newsItem.Id %>" class="deleteNewsItem" href="#"><img src="Content/Images/File-Delete-icon.png" /></a></td>
        </tr>
    <% } %>        
    </table>
 </fieldset>

    <p>
        <%= Html.ActionLink("Nieuw Bericht", "Create") %>
    </p>

<script type="text/javascript">
$('.deleteNewsItem').click(function(event) {        
    var newsItemId = this.id.split('_')[1];    

    $.ajax({ url: "News/Delete", data: "newsItemId=" + newsItemId, context: document.body,
        success: function(val) {
        $('#newsItem_' + newsItemId).remove();
        }
    });
});
$('.deleteNewsItem').confirm();
</script>
</asp:Content>